package org.gitman.agentplatform.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;

public class Vertex {
	private Integer id;
	private Collection<Vertex> neighbours;
	private Collection<Vertex> inverseNeighbours;
	private boolean visited;
	private int distance;
	private Vertex parent;

	public boolean wasVisited() {
		return visited;
	}
	public void setVisited(boolean visited) {
		this.visited = visited;
	}
	public Vertex(Integer id){
		this.id = id;
		neighbours = new LinkedList<Vertex>();
		inverseNeighbours = new LinkedList<Vertex>();
	}	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Vertex){
			if(((Vertex) obj).getId().equals(id)){
				return true;
			}			
		}
		return false;
	}
	public void addNeighbour(Vertex v){
		neighbours.add(v);
		v.addInverseNeighbour(this);
	}	
	public Collection<Vertex> getNeighbours(){
		return neighbours;
	}	
	public boolean isNeighbour(Vertex v){
		return neighbours.contains(v);
	}	
	public void removeNeighbour(Vertex v){
		neighbours.remove(v);
		v.removeInverseNeighbours(this);
	}
	@Override
	public String toString() {
		StringBuilder builder =  new StringBuilder("[" + id + "]\n-->: ");
		for(Vertex v: neighbours){
			builder.append(v.getId() + " ");
		}
		builder.append("\n<--: ");
		for(Vertex v: inverseNeighbours){
			builder.append(v.getId() + " ");
		}		
		builder.append("\n");
		return builder.toString();
	}
	public void addInverseNeighbour(Vertex v){
		inverseNeighbours.add(v);
	}
	public void removeInverseNeighbours(Vertex v){
		inverseNeighbours.remove(v);
	}
	public Collection<Vertex> getInverseNeighbours(){
		return inverseNeighbours;
	}
	public Collection<Vertex> getNormalAndInverseNeighbours(){
		ArrayList<Vertex> list = new ArrayList<Vertex>(neighbours);
		list.addAll(inverseNeighbours);
		return list;
	}
	public Vertex getParent() {
		return parent;
	}
	public void setParent(Vertex parent) {
		this.parent = parent;
	}
	public int getDistance() {
		return distance;
	}
	public void setDistance(int distance) {
		this.distance = distance;
	}
	
}
